<?php
namespace Admin\Controller;
use Think\Controller;
class ClassController extends Controller {
    public function index(){
        $this->display();
    }
    public function classlist(){
		
		$classmodel=M('class');
		$classs=$classmodel->order('classid ')->select();
		$this->class=$classs;
		$this->display();
	}
	public function delclass($classid){
	$classmodel=M('class');	
	if (false!==$classmodel->where("classid=$classid")->delete()) {
            $this->success('删除成功！');
        } else {
            $this->error('删除失败');
        }
		
	}
    public   function acadd(){
        // $classname=$_POST['classname'];
        // $classdate=$_POST['classdate'];
        // $classplace=$_POST['classplace'];
        // $charge=$_POST['charge'];
        // $atel=$_POST['atel'];
        // $acontent=$_POST['acontent'];
        // $classmodel=M('class');
        // if ($classmodel->create()) {
            
        //     if (false !==$classmodel->add()) {
        //         //echo $user->getLastSql();
        //         $this->success('添加成功！', 'classlist');
        //     }
        //     else
        //     {
        //         $this->error('添加失败','classlist');
        //     }
        // }
        // }



        $classs = D('class'); 
              $classid=I('post.classid');
        $data['classname']=I('post.classname');
        $data['classcontent']=I('post.classcontent');
        $data['classdate']=I('post.classdate');
        $data['classplace']=I('post.classplace');
        $data['classpicture']=I('post.classpicture');
        $data['classprice']=I('post.classprice');
        $data['classphone']=I('post.classphone');  
        $data['classinstruction']=I('post.classinstruction');
        // $data['classid']=S('classid');
        dump($data);
        
         if(false!==$classs->add($data)){
             $this->success('成功','classlist');
         }else{
            $this->error('失败','classlist');
         }
        }


        public function MyUpload(){

// $_FILES["file"]["error"] =0 表示文件上传成功！！
// $_FILES["file"]["error"] =1上传的文件超过了 php.ini 中 upload_max_filesize 选项限制的值.
// $_FILES["file"]["error"] =2上传文件的大小超过了 HTML 表单中 MAX_FILE_SIZE 选项指定的值。
// $_FILES["file"]["error"] =3文件只有部分被上传
// $_FILES["file"]["error"] =4没有文件被上传
// $_FILES["file"]["error"]>0 表示文件上传错误!!!
    $upload = new \Think\Upload();// 实例化上传类
    $upload->maxSize   =     3145728 ;// 设置附件上传大小
    $upload->exts      =     array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
    $upload->rootPath  =     './Public/Admin/photo/'; // 设置附件上传根目录
    $upload->autoSub   = false;//关闭子目录，默认ture
    //$info=$upload->uploadOne($_FILES['file']);  //上传文件

    //$upload->savePath  =     ''; // 设置附件上传（子）目录
    $upload->savename = 'time';

    $info   =   $upload->upload();  // 上传文件 
    //$dump(info);
    if(!$info) {        $this->error($upload->getError());    }
    else{return $info;}
    
    // else{        $this->success('上传成功！');    }  
    }

        public   function editac(){

              $classs = D('class'); 
              $classid=I('post.classid');
        $data['classname']=I('post.classname');
        $data['classcontent']=I('post.classcontent');
        $data['classdate']=I('post.classdate');
        $data['classplace']=I('post.classplace');
        $data['classpicture']=I('post.classpicture');
        $data['classphone']=I('post.classphone');  
        $data['classprice']=I('post.classprice');
        $data['classinstruction']=I('post.classinstruction');
        dump($data);
        if(false !== $classs->where("classid=$classid")->save($data)){
            $this->success('成功','classlist');
         }else{
            $this->error('失败');
         }
        }
        public function edit(){    
            $classs = D('class'); 
            $classid=$_GET['classid'];
            $res= $classs->where("classid=$classid")->find();
            $this->class=$res;
         
        $this->display();
        }
}